﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace ExcelFileQueryTool
{
    public static class Utility
    {
        public static string GetFirstChildFolderFromParent(string folder, string pattern)
        {
            if (string.IsNullOrEmpty(folder))
                throw new ArgumentNullException("folder");

            folder = folder.Trim();

            if (folder.EndsWith("\\"))
                folder = folder.TrimEnd('\\');

            var folders = Directory.GetDirectories(Directory.GetParent(folder).FullName, pattern, SearchOption.TopDirectoryOnly);

            if (folders == null || folders.Length == 0)
                return null;

            return folders[0];
        }
    }
}
